class ProvidersController < ApplicationController

  include ApplicationHelper

  # POST /providers
  # POST /providers.xml
  def create
    @provider = Provider.new(params[:provider])
    @provider.user = current_user
    
    respond_to do |format|
      if @provider.save
        flash[:notice] = 'Provider was successfully created.'
        format.html { redirect_to :controller=>'account', :action=>'settings' }
        format.xml  { head :created, :location => provider_url(@provider) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @provider.errors.to_xml }
      end
    end
  end

  # PUT /providers/1
  # PUT /providers/1.xml
  def update
    @provider = Provider.find(params[:id])

    respond_to do |format|
      if @provider.update_attributes(params[:provider])
        flash[:notice] = 'Provider was successfully updated.'
        format.html { redirect_to :controller=>'account', :action=>'settings' }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @provider.errors.to_xml }
      end
    end
  end

  # DELETE /providers/1
  # DELETE /providers/1.xml
  def destroy
    @provider = Provider.find(params[:id])
    @provider.destroy

    respond_to do |format|
      format.html { redirect_to :controller=>'account', :action=>'settings' }
      format.xml  { head :ok }
    end
  end
end
